#
# Package.
#

package iSOCK;

#
# Dependencies.
#

use File::Basename qw( dirname );
use Moose;
use namespace::autoclean;
use version;

#
# Base.
#

use Catalyst::Runtime '5.80';

use Catalyst qw(
  Authentication
  ConfigLoader
  Session
  Session::State::Cookie
  Session::Store::File
  StackTrace
  Static::Simple
);

#
# Version.
#

our $VERSION = qv( "0.28.0_78" );

#
# Setup.
#

my $tmp_root     = 'root/tmp';
my $upload_root  = "$tmp_root/.upload";
my $session_root = 'root/.session';

__PACKAGE__->config (
  name => 'iSOCK',
  
  default_path => '/report/radiator',
  default_view => 'HTML',
  
  navigation_tabs => [ qw( Documentation Login Component Product Status Abstract Logs Diff Subversion Download Logout ) ],
  
  log_stems => [ qw(
    isock_specification
    isock_datasheet
    isock_subversion
    sock_product_vs_product
    sock_commit_integration
    sock_followup_to_whatever
    sock_specification_to_spirit
    sock_annotate_datasheets
    sock_spirit_to_diagram
    sock_spirit_to_abstract
    sock_spirit_to_api
    sock_spirit_to_followup
    sock_spirit_to_verilog_pios
    sock_spirit_to_tcl
    sock_spirit_to_pio_sheet
    sock_lint_datasheet
    sock_atp_to_subversion
  ) ],
  
  directory => {
    sock => 'root/SOCK',
    tmp  => $tmp_root,
    adu  => '/local/local/flow_data/SOCKs/PRODUCTION/ADU/atmel-devices-utils-1.0.158', # /2/rfo_desflow/flow/ADU/atmel-devices-utils-1.0.158 -> ~flow/ADU/atmel-devices-utils-1.0.158
    www  => '/local/local/flow_data/SOCKs/PRODUCTION/WWW',                             # /2/rfo_desflow/flow/WWW                             -> ~flow/WWW
  },
  
  smtp_host       => 'rfomail.rfo.atmel.com',
  
  self_mail       => '"Monsieur Chaussette" <monsieur.chaussette@atmel.com>',
  
  root_id         => 'xcaron',
  root_name       => 'Xavier Caron',
  root_mail       => '"Xavier Caron" <xavier.caron@atmel.com>',
  
  subversion_user => 'flow',
  database_user   => 'flow',
  
  harvest_url     => 'http://norvm-tools-m.norway.atmel.com/hudson/view/Atmel%20Studio/job/atmel-devices-sam-harvest',
  harvest_token   => 'iSOCK',
  
 #integration => { # FIXME use this in iSOCK::Schema::App::Result::Product class?
 #  wiki_url_head => 'http://penfret.rfo.atmel.com/twiki/bin/view/DesignIntegration',
 #  wiki_url_tail => '_Project_Status',
 #},
  
  #
  # Plugins.
  #
  
  session => {
    storage        => $session_root,
    expires        => 100000,
    flash_to_stash => 1,
  },
  
  'Plugin::Static::Simple' => {
    dirs => [ qw( css images js ) ],
  },
  
  uploadtmp => $upload_root,
  
  model => {
   #app => {
   #  connect_info => { dsn => "dbi:SQLite:$db_root/app.db" },                                                              # currently hard-coded in iSOCK::Model::App
   #},
   #bugzilla => {
   #  ip = {
   #    connect_info => { dsn => 'dbi:mysql:host=10.159.240.146;user=bugread;password=bugread;database=bugs_at91ip'      }, # from iSOCK::Model::App::bug_tracker_dsn ( $type ) -- in ComponentType DB
   #  },
   #  analog = {
   #    connect_info => { dsn => 'dbi:mysql:host=10.159.240.146;user=bugread;password=bugread;database=bugs_at91analog'  }, # from iSOCK::Model::App::bug_tracker_dsn ( $type ) -- in ComponentType DB
   #  },
   #  digital = {
   #    connect_info => { dsn => 'dbi:mysql:host=10.159.240.146;user=bugread;password=bugread;database=bugs_at91digital' }, # from iSOCK::Model::App::bug_tracker_dsn ( $type ) -- in ComponentType DB
   #  },
   #  memory = {
   #    connect_info => { dsn => 'dbi:mysql:host=10.159.240.146;user=bugread;password=bugread;database=bugs_ceips'       }, # from iSOCK::Model::App::bug_tracker_dsn ( $type ) -- in ComponentType DB
   #  },
   #},
  },
  
  authentication => {
    default_realm => 'ldap',
    realms => {
      db => {
        class              => 'SimpleDB',
        user_model         => 'App::User',
        password_type      => 'hashed',
        password_hash_type => 'SHA-1',
      },
      ldap => {
        credential => {
          class          => 'Password',
          password_field => 'password',
          password_type  => 'self_check',
        },
        store => {
          class       => 'LDAP',
          ldap_server => 'rfodc01.rfo.atmel.com',
          binddn      => 'CORP\\rfoflowweb',
          bindpw      => 'Mdp4fl0ww3b',
          user_basedn => 'dc=corp, dc=atmel, dc=com',
          user_filter => '(&(objectClass=organizationalPerson)(objectClass=user)(sAMAccountName=%s))',
          user_field  => 'samaccountname',
        },
      },
    },
  },
);

unless ( -d $upload_root ) {
  my $directory;

  for ( split '/', $upload_root ) {
    $directory .= "$_/";

    next if -d $directory;

    mkdir $directory, oct '755' or die "Could not make '$directory' directory (part of '$upload_root' one)!";
  }
}

{
  no warnings 'uninitialized';

  __PACKAGE__->config->{using_front_end_proxy} = $ENV{CATALYST_ENGINE} eq 'HTTP::Prefork';
}

__PACKAGE__->setup;

sub version_string {
  return "iSOCK v$VERSION";
}

#
# Documentation.
#

=head1 NAME

iSOCK - Catalyst based application

=head1 SYNOPSIS

    script/isock_server.pl

=head1 DESCRIPTION

[enter your description here]

=head1 SEE ALSO

L<iSOCK::Controller::Root>, L<Catalyst>

=head1 AUTHOR

Xavier Caron

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

=head1 METHODS

=cut

#
# True.
#

1;
